package com.cn.etv;

/*
 * author:jiangtao
 * datetime:2011-12-28
 * description:main windows
 */
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

import com.cn.etv.CopyOfMain.ViewHolder;
import com.cn.etv.common.GetData;
import com.cn.etv.model.FilmDO;
import com.cn.etv.model.FilmPlayDO;
import com.cn.etv.model.FilmTypeDO;
import com.cn.etv.model.FilmTypeDescDO;
import com.cn.etv.model.SeriesDO;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.NetworkInfo.State;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.provider.Settings;
import android.text.method.ScrollingMovementMethod;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Gallery;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;
import android.widget.Toast;

public class Main extends Activity {
//	private GridView gridview;
//	顶部频道
	private String channel = "4";
//	影片细类
	private String type="1";
//	影片列表页数
	private String page = "1";
//	影片大类序列号
	private int ftype=0;
//	广告词
	private String banner = null;
//	细类显示列数控制
	private int begin=0;
	private int end=1;
	private int increment=1;
//	影片列表
	private List<FilmDO> filmList = new ArrayList<FilmDO>();
//	影片大类列表
	private List<FilmTypeDO> filmTypeList = new ArrayList<FilmTypeDO>();
//	影片细类列表
	private List<FilmTypeDescDO> filmTypeDescList = new ArrayList<FilmTypeDescDO>();
//	影片集数列表
	private List<SeriesDO> seriesDOList = new ArrayList<SeriesDO>();
//	private String typesId;
//	private String typesNum;
//	private List<FilmDO> filmList;
//	private List<FilmTypeDO> filmTypeList;
//	private List<FilmTypeDescDO> filmTypeDescList;
//	登陆成功后返回信息
	List list = new ArrayList();
//	private String[] titles = new String[] {"狂野飞车", "狂野飞车", "狂野飞车", "狂野飞车", "狂野飞车", "狂野飞车", "狂野飞车", "狂野飞车", "狂野飞车", "狂野飞车", "狂野飞车", "狂野飞车"};
//	private String[] play = new String[] {"播放", "播放", "播放", "播放", "播放", "播放", "播放", "播放", "播放", "播放", "播放", "播放"};
//	private String[] desc = new String[] {"介绍", "介绍", "介绍", "介绍", "介绍", "介绍", "介绍", "介绍", "介绍", "介绍", "介绍", "介绍"};
//	private String[] filmtype = new String[] {"狂野飞车", "狂野飞车", "狂野飞车", "狂野飞车", "狂野飞车", "狂野飞车", "狂野飞车", "狂野飞车", "狂野飞车", "狂野飞车", "狂野飞车", "狂野飞车", "狂野飞车", "狂野飞车"};
//	private String[] filmarea = new String[] {"播放", "播放", "播放", "播放", "播放", "播放", "播放", "播放", "播放", "播放", "播放", "播放"};
//	private String[] filmyear = new String[] {"介绍", "介绍", "介绍", "介绍", "介绍", "介绍", "介绍", "介绍", "介绍", "介绍", "介绍", "介绍"};
//	private String[] filmid = new String[] {"介绍1", "介绍2", "介绍3", "介绍4", "介绍5", "介绍6", "介绍7", "介绍8", "介绍9", "介绍10", "介绍11", "介绍12"};
//	private int[] images = { 
//    R.drawable.pic, R.drawable.pic,R.drawable.pic, R.drawable.pic,
//    R.drawable.pic, R.drawable.pic,R.drawable.pic, R.drawable.pic,
//    R.drawable.pic, R.drawable.pic,R.drawable.pic, R.drawable.pic
//     };
//	private int[] icons = { 
//            R.drawable.play, R.drawable.play,R.drawable.play, R.drawable.play,
//            R.drawable.play, R.drawable.play,R.drawable.play, R.drawable.play,
//            R.drawable.play, R.drawable.play,R.drawable.play, R.drawable.play
//             };
//	private int[] icons1 = { 
//            R.drawable.desc, R.drawable.desc,R.drawable.desc, R.drawable.desc,
//            R.drawable.desc, R.drawable.desc,R.drawable.desc, R.drawable.desc,
//            R.drawable.desc, R.drawable.desc,R.drawable.desc, R.drawable.desc
//             };
//	影片名称
	private String[] titles = new String[] {};
	private String[] play = new String[] {};
	private String[] desc = new String[] {};
	private String[] filmtypename = new String[] {};
//	private String[] filmarea = new String[] {"播放", "播放", "播放", "播放", "播放", "播放", "播放", "播放", "播放", "播放", "播放", "播放"};
//	private String[] filmyear = new String[] {"介绍", "介绍", "介绍", "介绍", "介绍", "介绍", "介绍", "介绍", "介绍", "介绍", "介绍", "介绍"};
	private String[] filmid = new String[] {};
	private String[] filmtype = new String[] {};
//	影片图片
	private String[] picurl = new String[] {};
	private int[] images = new int[] {};
	private int[] icons = new int[] {};
	private String[] filmtypeid = new String[] {};
	private int[] icons1 = new int[] {};
//	分辨率
	private DisplayMetrics metrics = new DisplayMetrics();
//	输入搜索影片名
	private String name;
//	private int[] playtype = new int[] {};
////	上一页点击事件
//	OnClickListener lPrev = new ImageView.OnClickListener(){
//		public void onClick(View v){
//			if(!page.equals("1")){
//				page=Integer.toString(Integer.parseInt(page)-1);
////				imageViewPrev.setImageDrawable(getResources().getDrawable(R.drawable.prev1));
////				imageViewPrev.setScaleType(ImageView.ScaleType.FIT_XY);
////				imageViewPrev.setLayoutParams(new Gallery.LayoutParams(85,48));
////				onPause();
////				filmList.clear();
////				Log.w("长度：",Integer.toString(filmList.size()));
////				filmList = GetData.getFilmList(Main.this,channel,type,page,list);
//				showActivity1("com.cn.etv","com.cn.etv.Main",channel,type,page,begin,ftype);
////				onResume();
//			}
//		}
//	};
//	
////	下一页点击事件
//	OnClickListener lNext = new ImageView.OnClickListener(){
//		public void onClick(View v){
//			page=Integer.toString(Integer.parseInt(page)+1);
////			imageViewNext.setImageDrawable(getResources().getDrawable(R.drawable.next1));
////			imageViewNext.setScaleType(ImageView.ScaleType.FIT_XY);
////			imageViewNext.setLayoutParams(new Gallery.LayoutParams(85,48));
////			onPause();
////			filmList.clear();
////			Log.w("长度：",Integer.toString(filmList.size()));
////			filmList = GetData.getFilmList(Main.this,channel,type,page,list);
//			showActivity1("com.cn.etv","com.cn.etv.Main",channel,type,page,begin,ftype);
////			onResume();
////			LayoutParams params=(LayoutParams) linearLayout.getLayoutParams();
////			params.height=90;
////			params.width=120;
////			linearLayout.setLayoutParams(params);
////			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
////			showDialog(str);
//			
//		}
//	};
	public void onDestroy(){
//		unregisterReceiver(mNetworkStateReceiver); //取消监听
		super.onDestroy();
	}
	public void onPause(){
//		filmList = new ArrayList<FilmDO>();
//		filmTypeList = new ArrayList<FilmTypeDO>();
//		filmTypeDescList = new ArrayList<FilmTypeDescDO>();
//		titles = new String[] {};
//		play = new String[] {};
//		desc = new String[] {};
//		filmtypename = new String[] {};
//		filmid = new String[] {};
//		filmtype = new String[] {};
//		picurl = new String[] {};
//		images = new int[] {};
//		icons = new int[] {};
//		filmtypeid = new String[] {};
//		icons1 = new int[] {};
//		playtype = new int[] {};
		super.onPause();
	}
//	主窗体
	public void onResume(){
		Log.w("onResume","start");
		//注册网络监听
//        IntentFilter filter = new IntentFilter();        
//        filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
//        registerReceiver(mNetworkStateReceiver, filter);
//		初始化数据
		init();
//		Log.w("11111111111111111:","1111111111111111111");
//    	填充影片大类
    	fillingFilmChannel();
//　　　填充影片分类
    	fillingFilmType();
//    	Log.w("fillingFilmType:","2222222222222222222222222");
//		填充返回按钮
//    	fillingReturnButton();
//    	Log.w("fillingReturnButton:","3333333333333333333333333");
//		填充影片部分
//    	onResume();
		fillingFilmList();
//		Log.w("fillingFilmList:","4444444444444444444444444");
//      填充翻页按钮
		fillingChangePage();
//		Log.w("fillingChangePage:","5555555555555555555555555");
//      填充广告语
     	fillingBanner();
//     	Log.w("fillingBanner:","666666666666666666666666");
     	Log.w("onResume","end");
		super.onResume();
	}
	private void init(){
		Intent intent = getIntent();
		String account = intent.getStringExtra("account");
		String pwd = intent.getStringExtra("pwd");
		String mac = intent.getStringExtra("mac");
		if(intent.getStringExtra("page")!=null){
			page = intent.getStringExtra("page");
		}
		if(intent.getStringExtra("channel")!=null){
			channel = intent.getStringExtra("channel");
		}
		if(intent.getStringExtra("type")!=null){
			type = intent.getStringExtra("type");
		}
		if(intent.getStringExtra("name")!=null){
			name = intent.getStringExtra("name");
		}
//		begin = intent.getIntExtra("begin", begin);
//		end = begin+increment;
		if(account==null){
			account="c3739aeec1d29ef5";
			pwd="";
			mac="18:87:96:5B:4D:9E";
			Log.i("主程序注册:","开始注册");
//	        Intent mBootIntent = new Intent();
//	        mBootIntent.setComponent(new ComponentName("com.cn.etv","com.cn.etv.Register"));
//	        mBootIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//			Main.this.startActivity(mBootIntent);
		}
//		Log.i("账户：",account);
		list = GetData.login(Main.this,account,pwd,mac);
//		if((Integer)list.get(0)!=0){
//			HttpClientUtil.setCookie((HttpResponse) list.get(3),"http://etv.easy3c.net/list.php",(String) list.get(1),(String) list.get(2));
//		}
		if(filmList.size()==0 || !channel.equals(8)){
			filmList = GetData.getFilmList(Main.this,channel,type,page,list);
//		filmTypeDescList = GetData.getFilmTypeDescList(Main.this,channel,type);
		} else {
			if(filmList.size()==0 || channel.equals(8)){
				filmList = GetData.getFilmListByName(Main.this,channel,type,page,name,list);
			}
		}
		if(banner==null){
			banner = GetData.getBanner(Main.this,channel);
		}
		if(filmTypeList.size()==0){
//			Log.w("asdfasdasdasdfasdfasd","sdfasdfasdfasdfsadfsad");
			filmTypeList = GetData.getFilmTypeList(Main.this,channel);
		}
		int filmListLength=0;
		if(filmList.size()!=0){
//			Log.i("filmList:",Integer.toString(filmList.size()));
			if(filmList.size()>12){
				filmListLength=12;
			} else {
				filmListLength=filmList.size();
			}
			FilmDO filmDO = new FilmDO();
//			Log.w("filmListLength",Integer.toString(filmListLength));
			titles=new String[filmListLength];
			play=new String[filmListLength];
			desc=new String[filmListLength];
			images=new int[filmListLength];
			icons=new int[filmListLength];
			icons1=new int[filmListLength];
			filmid=new String[filmListLength];
			picurl=new String[filmListLength];
			filmtype=new String[filmListLength];
//			playtype=new int[filmListLength];
			for(int i=0; i<filmListLength; i++){
				filmDO=filmList.get(i);
//				Log.w("film id"+i+":",filmDO.getId());
//				Log.w("film name"+i+":",filmDO.getName());
//				Log.w("film pic"+i+":",filmDO.getPic());
				if(filmDO.getName().length()>14){
					titles[i]=filmDO.getName().substring(0, 13)+"...";
				} else {
					titles[i]=filmDO.getName();
				}
//				play[i]="播放";
//				desc[i]="介绍";
//				images[i]=R.drawable.pic;
//				icons[i]=R.drawable.play;
//				icons1[i]=R.drawable.desc;
				filmid[i]=filmDO.getId();
				if(filmDO.getPic()!=null){
					picurl[i]="http://"+filmDO.getPic();
				}
				filmtype[i]=filmDO.getType();
			}
		}
//		Log.i("filmTypeList size:",Integer.toString(filmTypeList.size()));
		if(filmTypeList.size()>0){
			ftype=intent.getIntExtra("ftype", ftype);
//			for(int i=0; i<filmTypeList.size(); i++){
//				Log.i("filmTypeList name:",filmTypeList.get(i).getName());
//				if(i==0){
//					filmTypeDescList=filmTypeList.get(i).getFilmTypeDescDOList();
//					Log.w("filmTypeDescList size:",Integer.toString(filmTypeDescList.size()));
//				}
//			}
//			Log.i("filmTypeList size:",Integer.toString(filmTypeList.size()));
//			Log.i("dddddddddddddddddddddddddddd",filmTypeList.get(ftype).getName());
//			Log.i("dddddddddddddddddddddddddddd",Integer.toString(ftype));
			filmTypeDescList=filmTypeList.get(ftype).getFilmTypeDescDOList();
//			Log.w("filmTypeDescList size:",Integer.toString(filmTypeDescList.size()));
		}
	}
	private void fillingFilmChannel() {
		// TODO Auto-generated method stub
		TableRow channelRow = (TableRow) findViewById(R.id.tableRow1);
		LinearLayout linearLayout = new LinearLayout(Main.this);
		ImageView imageView = new ImageView(Main.this);
		if(channel.equals("4")){
			imageView.setImageDrawable(getResources().getDrawable(R.drawable.child1));
	    	imageView.setScaleType(ImageView.ScaleType.FIT_XY);
	    	imageView.setLayoutParams(new Gallery.LayoutParams(175,97));
		} else {
			imageView.setImageDrawable(getResources().getDrawable(R.drawable.child));
	    	imageView.setScaleType(ImageView.ScaleType.FIT_XY);
	    	imageView.setLayoutParams(new Gallery.LayoutParams(155,41));
			OnClickListener child = new TextView.OnClickListener(){
	    		public void onClick(View v){
	    			channel="4";
	    			showActivity1("com.cn.etv","com.cn.etv.Main",channel,type,page,begin,ftype);
	    		}
	    	};
	    	imageView.setOnClickListener(child);
		}
    	linearLayout.addView(imageView);
    	LinearLayout linearLayout1 = new LinearLayout(Main.this);
		ImageView imageView1 = new ImageView(Main.this);
		if(channel.equals("1")){
			imageView1.setImageDrawable(getResources().getDrawable(R.drawable.tv1));
	    	imageView1.setScaleType(ImageView.ScaleType.FIT_XY);
	    	imageView1.setLayoutParams(new Gallery.LayoutParams(175,97));
		} else {
			imageView1.setImageDrawable(getResources().getDrawable(R.drawable.tv));
	    	imageView1.setScaleType(ImageView.ScaleType.FIT_XY);
	    	imageView1.setLayoutParams(new Gallery.LayoutParams(155,41));
			OnClickListener tv = new TextView.OnClickListener(){
	    		public void onClick(View v){
	    			channel="1";
	    			showActivity1("com.cn.etv","com.cn.etv.Main",channel,type,page,begin,ftype);
	    		}
	    	};
	    	imageView1.setOnClickListener(tv);
		}
    	linearLayout1.addView(imageView1);
    	LinearLayout linearLayout2 = new LinearLayout(Main.this);
		ImageView imageView2 = new ImageView(Main.this);
    	if(channel.equals("2")){
			imageView2.setImageDrawable(getResources().getDrawable(R.drawable.film1));
	    	imageView2.setScaleType(ImageView.ScaleType.FIT_XY);
	    	imageView2.setLayoutParams(new Gallery.LayoutParams(175,97));
		} else {
			imageView2.setImageDrawable(getResources().getDrawable(R.drawable.film));
	    	imageView2.setScaleType(ImageView.ScaleType.FIT_XY);
	    	imageView2.setLayoutParams(new Gallery.LayoutParams(155,41));
			OnClickListener film = new TextView.OnClickListener(){
	    		public void onClick(View v){
	    			channel="2";
	    			showActivity1("com.cn.etv","com.cn.etv.Main",channel,type,page,begin,ftype);
	    		}
	    	};
	    	imageView2.setOnClickListener(film);
		}
    	linearLayout2.addView(imageView2);
    	LinearLayout linearLayout3 = new LinearLayout(Main.this);
		ImageView imageView3 = new ImageView(Main.this);
    	if(channel.equals("6")){
			imageView3.setImageDrawable(getResources().getDrawable(R.drawable.arts1));
	    	imageView3.setScaleType(ImageView.ScaleType.FIT_XY);
	    	imageView3.setLayoutParams(new Gallery.LayoutParams(175,97));
		} else {
			imageView3.setImageDrawable(getResources().getDrawable(R.drawable.arts));
	    	imageView3.setScaleType(ImageView.ScaleType.FIT_XY);
	    	imageView3.setLayoutParams(new Gallery.LayoutParams(155,41));
			OnClickListener arts = new TextView.OnClickListener(){
	    		public void onClick(View v){
	    			channel="6";
	    			showActivity1("com.cn.etv","com.cn.etv.Main",channel,type,page,begin,ftype);
	    		}
	    	};
//	    	imageView3.setOnClickListener(arts);
		}
    	linearLayout3.addView(imageView3);
    	LinearLayout linearLayout4 = new LinearLayout(Main.this);
		ImageView imageView4 = new ImageView(Main.this);
    	if(channel.equals("7")){
			imageView4.setImageDrawable(getResources().getDrawable(R.drawable.music1));
	    	imageView4.setScaleType(ImageView.ScaleType.FIT_XY);
	    	imageView4.setLayoutParams(new Gallery.LayoutParams(175,97));
		} else {
			imageView4.setImageDrawable(getResources().getDrawable(R.drawable.music));
	    	imageView4.setScaleType(ImageView.ScaleType.FIT_XY);
	    	imageView4.setLayoutParams(new Gallery.LayoutParams(155,41));
			OnClickListener music = new TextView.OnClickListener(){
	    		public void onClick(View v){
	    			channel="7";
	    			showActivity1("com.cn.etv","com.cn.etv.Main",channel,type,page,begin,ftype);
	    		}
	    	};
//	    	imageView4.setOnClickListener(music);
		}
    	linearLayout4.addView(imageView4);
    	LinearLayout linearLayout5 = new LinearLayout(Main.this);
		ImageView imageView5 = new ImageView(Main.this);
    	if(channel.equals("8")){
    		imageView5.setImageDrawable(getResources().getDrawable(R.drawable.search1));
    		imageView5.setScaleType(ImageView.ScaleType.FIT_XY);
    		imageView5.setLayoutParams(new Gallery.LayoutParams(175,97));
		} else {
			imageView5.setImageDrawable(getResources().getDrawable(R.drawable.search));
			imageView5.setScaleType(ImageView.ScaleType.FIT_XY);
			imageView5.setLayoutParams(new Gallery.LayoutParams(155,41));
			OnClickListener search = new TextView.OnClickListener(){
	    		public void onClick(View v){
	    			channel="8";
	    			showDialogSearch();
	    		}
	    	};
	    	imageView5.setOnClickListener(search);
		}
    	linearLayout5.addView(imageView5);
    	channelRow.addView(linearLayout);
    	channelRow.addView(linearLayout1);
    	channelRow.addView(linearLayout2);
    	channelRow.addView(linearLayout3);
    	channelRow.addView(linearLayout4);
    	channelRow.addView(linearLayout5);
	}
	public void onCreate(Bundle savedInstanceState) {
//		解除锁屏
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD,WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
//		窗口显示时，隐藏所有的屏幕装饰（例如状态条）。使窗口占用整个显示区域。
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
		super.onCreate(savedInstanceState);
//		填充标题栏
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.main);
//		获取屏幕分辨率
		getWindowManager().getDefaultDisplay().getMetrics(metrics);
		
		//注册网络监听
//        IntentFilter filter = new IntentFilter();        
//        filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
//        registerReceiver(mNetworkStateReceiver, filter);
//		try {
//			ReadWriteFile.creatTxtFile();
//		} catch (IOException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
		Log.i("分辨率：",Integer.toString(metrics.heightPixels)+'*'+Integer.toString(metrics.widthPixels));
		
//		LinearLayout ll=new LinearLayout(Main.this);
////		ll.setPadding(200, 200, 0, 0);
//		ImageView ii=new ImageView(Main.this);//初始化ImageView 
//		ii.setImageDrawable(getResources().getDrawable(images[0]));//设置图片 
//		ii.setScaleType(ImageView.ScaleType.FIT_XY);
//		Log.i("left:", Integer.toString(ii.getLeft()));
//		ii.setLayoutParams(new Gallery.LayoutParams(150,98));
//		ii.setBackgroundResource(R.drawable.ic_launcher);
//		LinearLayout.LayoutParams param3 = new LinearLayout.LayoutParams(200, 98);
//        param3.setMargins(20, 150, 0, 0);
//        ii.setLayoutParams(param3);
////		ii.setPadding(ii.getPaddingLeft()+200, ii.getPaddingTop()+100, 0, 0);
//		ll.addView(ii);
//		LinearLayout lll=new LinearLayout(Main.this);
//		ImageView iii=new ImageView(Main.this);//初始化ImageView 
//		iii.setImageDrawable(getResources().getDrawable(images[0]));//设置图片 
//		iii.setScaleType(ImageView.ScaleType.FIT_XY);
//		Log.i("left:", Integer.toString(iii.getLeft()));
//		iii.setLayoutParams(new Gallery.LayoutParams(150,98));
//		iii.setBackgroundResource(R.drawable.ic_launcher);
//		LinearLayout.LayoutParams param4 = new LinearLayout.LayoutParams(200, 98);
//        param3.setMargins(180, 0, 0, 0);
//        iii.setLayoutParams(param4);
//		lll.addView(iii);
//		BaseAdapter ba=new BaseAdapter(){//为ListView准备内容适配器 
//			public int getCount() {return 5;}//总共5个选项 
//			public Object getItem(int arg0) { return null; } 
//			public long getItemId(int arg0) { return 0; } 
//			public View getView(int arg0, View arg1, ViewGroup arg2) { 
//			//动态生成每个下拉项对应的View，每个下拉项View由LinearLayout 
//			//中包含一个ImageView及一个TextView构成 
//				LinearLayout ll=new LinearLayout(Main.this);//初始化LinearLayout 
//				ll.setOrientation(LinearLayout.HORIZONTAL); //设置朝向 
//				ll.setPadding(5,5,5,5);//设置四周留白 
//				ImageView ii=new ImageView(Main.this);//初始化ImageView 
//				ii.setImageDrawable(getResources().getDrawable(images[0]));//设置图片 
//				ii.setScaleType(ImageView.ScaleType.FIT_XY); 
//				ii.setLayoutParams(new Gallery.LayoutParams(100,98)); 
//				ll.addView(ii);//添加到LinearLayout中 
//				TextView tv=new TextView(Main.this);//初始化TextView 
//				tv.setText(titles[0]);//设置内容 
//				tv.setTextSize(24);//设置字体大小  
//				tv.setPadding(5,5,5,5);//设置四周留白 
//				tv.setGravity(Gravity.LEFT); 
//				ll.addView(tv);//添加到LinearLayout中 
//				return ll; 
//			} 
//		};
	}
		
//	介绍的点击事件
	private void showDialog(String filmid,String filmname,String pic,String type)
    {
       AlertDialog.Builder builder = new AlertDialog.Builder(this);
       FilmPlayDO filmPlayDO = GetData.getFilm(Main.this,filmid,filmname,pic,type);
       seriesDOList=filmPlayDO.getSeries();
       // 设置对话框的图标
//       builder.setIcon(android.R.drawable.ic_dialog_info);
       // 设置对话框的标题
//       builder.setTitle(title);
       // 设置对话框显示的信息
//       builder.setMessage(msg);
       // 设置对话框的按钮
//       builder.setPositiveButton("确定", null);
       LinearLayout linearlayout = new LinearLayout(Main.this);
//       LayoutParams params = (LayoutParams) linearlayout.getLayoutParams();
//       params.height = 300;
//       params.width = 300;
//       linearlayout.setLayoutParams(params);
       TableLayout tabFilmPlay = new TableLayout(Main.this);
       TableRow rowFilmPlay1 = new TableRow(Main.this);
       TableRow rowFilmPlay2 = new TableRow(Main.this);
       TableRow rowFilmPlay3 = new TableRow(Main.this);
       TableRow rowFilmPlay4 = new TableRow(Main.this);
       LinearLayout linearlayout1 = new LinearLayout(Main.this);
       LinearLayout linearlayout2 = new LinearLayout(Main.this);
       LinearLayout linearlayout3 = new LinearLayout(Main.this);
       LinearLayout linearlayout4 = new LinearLayout(Main.this);
       GridView gridView = new GridView(Main.this);
       gridView.setNumColumns(4);
       gridView.setPadding(10, 0, 10, 4);
       SeriesAdapter seriesAdapter = new SeriesAdapter(Main.this);
       seriesAdapter.setItems(seriesDOList);
       gridView.setAdapter(seriesAdapter);
       gridView.setOnItemClickListener(new ItemClickListener1());
//       Log.w("filmPlayDO.getName()",filmPlayDO.getName());
       TextView textView = new TextView(Main.this);
       textView.setText(filmPlayDO.getName());
       textView.setTextSize(18);
       textView.setWidth(1000);
       TextView textView1 = new TextView(Main.this);
       textView1.setText(filmPlayDO.getInfo());
       textView1.setTextSize(14);
       textView1.setSingleLine(false);
       textView1.setWidth(1000);
       textView1.setVerticalScrollBarEnabled(true);
       textView1.setMovementMethod(new ScrollingMovementMethod());
       ImageView imageView = new ImageView(Main.this);
	   Bitmap bitmap = GetData.getHttpBitmap(filmPlayDO.getPic());
	   imageView.setImageBitmap(bitmap);
	   imageView.setScaleType(ImageView.ScaleType.FIT_XY);
//	   imageView.setLayoutParams(new Gallery.LayoutParams(77,50));
//       linearLayoutReturn.setPadding(110, 10, 0, 0);
	   linearlayout1.setPadding(30, 10, 0, 5);
	   linearlayout1.addView(textView);
	   rowFilmPlay1.addView(linearlayout1);
	   linearlayout2.setPadding(30, 10, 0, 0);
	   linearlayout2.addView(imageView);
//       rowFilmPlay2.addView(linearlayout2);
       linearlayout3.setPadding(30, 10, 20, 10);
       linearlayout3.addView(textView1);
       linearlayout4.setPadding(10, 0, 10, 0);
       linearlayout4.addView(gridView);
//       rowFilmPlay3.addView(linearlayout3);
       rowFilmPlay4.addView(linearlayout4);
       tabFilmPlay.addView(rowFilmPlay1);
//       tabFilmPlay.addView(rowFilmPlay2);
//       tabFilmPlay.addView(rowFilmPlay3);
       tabFilmPlay.addView(rowFilmPlay4);
//	   linearlayout.addView(textView);
//	   linearlayout.addView(imageView);
       linearlayout.addView(tabFilmPlay);
       builder.setView(linearlayout);
       // 显示对话框
       builder.create().show();
       Intent intent;
    }
//	播放的点击事件
	private void showDialogPlay(String filmid,String filmname,String pic,String type)
    {
//       AlertDialog.Builder builder = new AlertDialog.Builder(this);
//       FilmPlayDO filmPlayDO = GetData.getFilm(Main.this,filmid,filmname,pic,type);
       // 设置对话框的图标
//       builder.setIcon(android.R.drawable.ic_dialog_info);
       // 设置对话框的标题
//       builder.setTitle(title);
       // 设置对话框显示的信息
//       builder.setMessage(msg);
       // 设置对话框的按钮
//       builder.setPositiveButton("确定", null);
//       LinearLayout linearlayout = new LinearLayout(Main.this);
//       LayoutParams params = (LayoutParams) linearlayout.getLayoutParams();
//       params.height = 300;
//       params.width = 300;
//       linearlayout.setLayoutParams(params);
//       TextView textView = new TextView(Main.this);
//       textView.setText(filmPlayDO.getInfo());
//       linearlayout.addView(textView);
       Intent mBootIntent = new Intent(Main.this,Detail.class);
       mBootIntent.putExtra("filmid", filmid);
       mBootIntent.putExtra("filmname", filmname);
       mBootIntent.putExtra("pic", pic);
       mBootIntent.putExtra("type", type);
       Main.this.startActivity(mBootIntent);
//       builder.setView(linearlayout);
       // 显示对话框
//       builder.create().show();
//       Intent intent;
    }
	private void showDialogSearch()
    {
       AlertDialog.Builder builder = new AlertDialog.Builder(this);
//       FilmPlayDO filmPlayDO = (FilmPlayDO) GetData.getFilmListByName(Main.this,channel,type,page,filmname,list);
//       seriesDOList=filmPlayDO.getSeries();
       // 设置对话框的图标
//       builder.setIcon(android.R.drawable.ic_dialog_info);
       // 设置对话框的标题
       builder.setTitle("搜索");
       // 设置对话框显示的信息
//       builder.setMessage(msg);
       // 设置对话框的按钮
//       builder.setPositiveButton("确定", null);
       LinearLayout linearlayout = new LinearLayout(Main.this);
//       LayoutParams params = (LayoutParams) linearlayout.getLayoutParams();
//       params.height = 300;
//       params.width = 300;
//       linearlayout.setLayoutParams(params);
       TableLayout tabFilmPlay = new TableLayout(Main.this);
       TableRow rowFilmPlay1 = new TableRow(Main.this);
       TableRow rowFilmPlay2 = new TableRow(Main.this);
       TableRow rowFilmPlay3 = new TableRow(Main.this);
       LinearLayout linearlayout1 = new LinearLayout(Main.this);
       LinearLayout linearlayout2 = new LinearLayout(Main.this);
       LinearLayout linearlayout3 = new LinearLayout(Main.this);
//       GridView gridView = new GridView(Main.this);
//       gridView.setNumColumns(4);
//       gridView.setPadding(10, 0, 10, 4);
//       SeriesAdapter seriesAdapter = new SeriesAdapter(Main.this);
//       seriesAdapter.setItems(seriesDOList);
//       gridView.setAdapter(seriesAdapter);
//       gridView.setOnItemClickListener(new ItemClickListener1());
////       Log.w("filmPlayDO.getName()",filmPlayDO.getName());
//       TextView textView = new TextView(Main.this);
//       textView.setText(filmPlayDO.getName());
//       TextView textView1 = new TextView(Main.this);
//       textView1.setText(filmPlayDO.getInfo());
//       textView1.setTextSize(14);
//       textView1.setSingleLine(false);
//       textView1.setWidth(800);
//       textView1.setVerticalScrollBarEnabled(true);
//       textView1.setMovementMethod(new ScrollingMovementMethod());
//       ImageView imageView = new ImageView(Main.this);
//	   Bitmap bitmap = GetData.getHttpBitmap(filmPlayDO.getPic());
//	   imageView.setImageBitmap(bitmap);
//	   imageView.setScaleType(ImageView.ScaleType.FIT_XY);
//	   imageView.setLayoutParams(new Gallery.LayoutParams(77,50));
//       linearLayoutReturn.setPadding(110, 10, 0, 0);
       TextView textView = new TextView(Main.this);
       textView.setText("名称：");
       final EditText editText = new EditText(Main.this);
       editText.setWidth(400);
       Button button = new Button(Main.this);
       button.setText("搜索");
       OnClickListener lSearch = new ImageView.OnClickListener(){
			public void onClick(View v){
				showActivity2("com.cn.etv","com.cn.etv.Main",channel,type,page,begin,ftype,editText.getText().toString());
			}
       };
       button.setOnClickListener(lSearch);
	   linearlayout1.setPadding(30, 0, 0, 0);
	   linearlayout1.addView(textView);
	   linearlayout1.addView(editText);
	   linearlayout1.addView(button);
	   rowFilmPlay1.addView(linearlayout1);
//	   linearlayout2.setPadding(30, 10, 0, 0);
//	   linearlayout2.addView(button);
//       rowFilmPlay2.addView(linearlayout2);
//       linearlayout3.setPadding(30, 10, 20, 10);
//       rowFilmPlay3.addView(linearlayout3);
       tabFilmPlay.addView(rowFilmPlay1);
//       tabFilmPlay.addView(rowFilmPlay2);
//       tabFilmPlay.addView(rowFilmPlay3);
//	   linearlayout.addView(textView);
//	   linearlayout.addView(imageView);
       linearlayout.addView(tabFilmPlay);
       builder.setView(linearlayout);
       // 显示对话框
       builder.create().show();
       Intent intent;
    }
//	主界面切换
	private void showActivity(String str,String str1){
		super.onCreate(null);
	    Intent mBootIntent = new Intent();
	    mBootIntent.setComponent(new ComponentName(str,str1));
	    mBootIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		Main.this.startActivity(mBootIntent);
	}
//	刷新页面数据
	private void showActivity1(String str,String str1,String channel,String type,String page,int begin,int ftype){
		super.onCreate(null);
	    Intent mBootIntent = new Intent();
	    mBootIntent.putExtra("channel", channel);
	    mBootIntent.putExtra("type", type);
	    mBootIntent.putExtra("page", page);
	    mBootIntent.putExtra("begin", begin);
	    mBootIntent.putExtra("ftype", ftype);
	    mBootIntent.setComponent(new ComponentName(str,str1));
	    mBootIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		Main.this.startActivity(mBootIntent);
	}
//	搜索
	private void showActivity2(String str,String str1,String channel,String type,String page,int begin,int ftype,String name){
		super.onCreate(null);
	    Intent mBootIntent = new Intent();
	    mBootIntent.putExtra("channel", channel);
	    mBootIntent.putExtra("type", type);
	    mBootIntent.putExtra("page", page);
	    mBootIntent.putExtra("begin", begin);
	    mBootIntent.putExtra("ftype", ftype);
	    mBootIntent.putExtra("name", name);
	    mBootIntent.setComponent(new ComponentName(str,str1));
	    mBootIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		Main.this.startActivity(mBootIntent);
	}
//	填充返回按钮
	private void fillingReturnButton(){
    	TableRow returnRow = (TableRow) findViewById(R.id.tableRow8);
    	LinearLayout linearLayoutReturn = new LinearLayout(Main.this);
		ImageView imageViewReturn = new ImageView(Main.this);
//		imageViewReturn.setImageDrawable(getResources().getDrawable(R.drawable.re));
		imageViewReturn.setScaleType(ImageView.ScaleType.FIT_XY);
		imageViewReturn.setLayoutParams(new Gallery.LayoutParams(77,50));
    	linearLayoutReturn.setPadding(110, 10, 0, 0);
    	linearLayoutReturn.addView(imageViewReturn);
    	returnRow.addView(linearLayoutReturn);
	}
	
//	填充翻页
	private void fillingChangePage(){
		TableRow rowPage = (TableRow) findViewById(R.id.tableRow4);
		final ImageView imageViewPrev = new ImageView(Main.this);
		final ImageView imageViewNext = new ImageView(Main.this);
        final LinearLayout linearLayoutPage = new LinearLayout(Main.this);
//		上一页点击事件
		OnClickListener lPrev = new ImageView.OnClickListener(){
			public void onClick(View v){
				if(!page.equals("1")){
					page=Integer.toString(Integer.parseInt(page)-1);
					imageViewPrev.setImageDrawable(getResources().getDrawable(R.drawable.prev1));
//					imageViewPrev.setScaleType(ImageView.ScaleType.FIT_XY);
//					imageViewPrev.setLayoutParams(new Gallery.LayoutParams(85,48));
//					onPause();
//					filmList.clear();
//					Log.w("长度：",Integer.toString(filmList.size()));
//					filmList = GetData.getFilmList(Main.this,channel,type,page,list);
					showActivity1("com.cn.etv","com.cn.etv.Main",channel,type,page,begin,ftype);
//					onResume();
				}
			}
		};
		
//		下一页点击事件
		OnClickListener lNext = new ImageView.OnClickListener(){
			public void onClick(View v){
				page=Integer.toString(Integer.parseInt(page)+1);
				imageViewNext.setImageDrawable(getResources().getDrawable(R.drawable.next1));
//				imageViewNext.setScaleType(ImageView.ScaleType.FIT_XY);
//				imageViewNext.setLayoutParams(new Gallery.LayoutParams(85,48));
//				linearLayoutPage.addView(imageViewNext);
//				onPause();
//				filmList.clear();
//				Log.w("长度：",Integer.toString(filmList.size()));
//				filmList = GetData.getFilmList(Main.this,channel,type,page,list);
				showActivity1("com.cn.etv","com.cn.etv.Main",channel,type,page,begin,ftype);
//				onResume();
//				LayoutParams params=(LayoutParams) linearLayout.getLayoutParams();
//				params.height=90;
//				params.width=120;
//				linearLayout.setLayoutParams(params);
//				SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
//				showDialog(str);
				
			}
		};
		
		TextView textView = new TextView(Main.this);
		textView.setText(" " + page + " ");
		textView.setTextSize(16);
		textView.setTextColor(Color.WHITE);
		imageViewPrev.setImageDrawable(getResources().getDrawable(R.drawable.prev));
		imageViewPrev.setScaleType(ImageView.ScaleType.FIT_XY);
		imageViewPrev.setLayoutParams(new Gallery.LayoutParams(85,48));
		imageViewPrev.setOnClickListener(lPrev);
		
//    	上一页点击事件
//    	OnClickListener lNext = new ImageView.OnClickListener(){
//    		public void onClick(View v){
////    			if(!page.equals("1")){
//    				page=Integer.toString(Integer.parseInt(page)+1);
//    				imageViewNext.setImageDrawable(getResources().getDrawable(R.drawable.next1));
//    				imageViewNext.setScaleType(ImageView.ScaleType.FIT_XY);
//    				imageViewNext.setLayoutParams(new Gallery.LayoutParams(85,48));
////    				onPause();
////    				filmList.clear();
////    				Log.w("长度：",Integer.toString(filmList.size()));
////    				filmList = GetData.getFilmList(Main.this,channel,type,page,list);
//    				showActivity1("com.cn.etv","com.cn.etv.Main",channel,type,page,begin,ftype);
////    				onResume();
////    			}
////    			LayoutParams params=(LayoutParams) linearLayout.getLayoutParams();
////    			params.height=90;
////    			params.width=120;
////    			linearLayout.setLayoutParams(params);
////    			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
////    			showDialog(str);
//    			
//    		}
//    	};
 		imageViewNext.setImageDrawable(getResources().getDrawable(R.drawable.next));
 		imageViewNext.setScaleType(ImageView.ScaleType.FIT_XY);
 		imageViewNext.setLayoutParams(new Gallery.LayoutParams(85,48));
 		imageViewNext.setOnClickListener(lNext);
     	linearLayoutPage.setPadding(430, 45, 20, 0);
     	linearLayoutPage.setGravity(Gravity.CENTER_VERTICAL);
     	linearLayoutPage.addView(imageViewPrev);
     	linearLayoutPage.addView(textView);
     	linearLayoutPage.addView(imageViewNext);
     	rowPage.addView(linearLayoutPage);
	}
	
//	填充广告语
	private void fillingBanner(){
     	TableRow rowBanner = (TableRow) findViewById(R.id.tableRow10);
     	TextView textviewBanner = new TextView(Main.this);
     	textviewBanner.setText(banner);
     	textviewBanner.setTextSize(14);
     	textviewBanner.setTextColor(Color.WHITE);
     	textviewBanner.setPadding(18, 0, 0, 0);
     	rowBanner.addView(textviewBanner);
	}
	
//	填充影片类别部分
	private void fillingFilmType(){
		TableLayout tabFilmType = (TableLayout) findViewById(R.id.tableLayout5);
//		影片细类列表
		LinearLayout filmTypeDesc = (LinearLayout) findViewById(R.id.linearLayout10);
		filmTypeDesc.setPadding(25, 15, 5, 0);
//		filmTypeDesc.addView(imageViewFilmType);
		GridView my_gridview = (GridView) findViewById(R.id.gridView1);
		ImageAdapter ia = new ImageAdapter(Main.this);
		ia.setItems(filmTypeDescList);
		my_gridview.setAdapter(ia);
		my_gridview.setOnItemClickListener(new ItemClickListener());
//		TableLayout tabFilmType = new TableLayout(Main.this);
//		TableRow rowFilmType = new TableRow(Main.this);
//		TableLayout tabFilmTypeDesc = new TableLayout(Main.this);
//		Log.i("length：",Integer.toString(filmTypeDescList.size()));
////		影片小类别按钮
//		for(int i=0; i<filmTypeDescList.size(); i++){
////			类型点击事件
//			final String type = filmTypeDescList.get(i).getId();
//			OnClickListener lFilmTypeDesc = new TextView.OnClickListener(){
//				public void onClick(View v){
//					showActivity1("com.cn.etv","com.cn.etv.Main",type,page,begin);
////					LayoutParams params=(LayoutParams) linearLayout.getLayoutParams();
////					params.height=90;
////					params.width=120;
////					linearLayout.setLayoutParams(params);
////					SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
////					showDialog(str);
//					
//				}
//			};
//			TableRow rowFilmTypeDesc = new TableRow(Main.this);
//			rowFilmTypeDesc.setPadding(0, 4, 0, 0);
//			TextView textview = new TextView(Main.this);
//	        textview.setText(filmTypeDescList.get(i).getName());
//	        textview.setTextSize(9);
//	        rowFilmTypeDesc.addView(textview);
//	        tabFilmTypeDesc.addView(rowFilmTypeDesc);
//		}
//		左滚动按钮（暂时无用）
//		OnClickListener lLeft = new TextView.OnClickListener(){
//			public void onClick(View v){
//				if(begin>=1){
//					begin=begin-1;
//					showActivity1("com.cn.etv","com.cn.etv.Main",channel,type,page,begin,ftype);
//				}
////				type=
////				filmList = GetData.getFilmList(Main.this,channel,type,value,page);
////				LayoutParams params=(LayoutParams) linearLayout.getLayoutParams();
////				params.height=90;
////				params.width=120;
////				linearLayout.setLayoutParams(params);
////				SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
////				showDialog(str);
//			}
//		};
//		LinearLayout linearLayoutLeft = new LinearLayout(Main.this);
//		ImageView imageViewLeft = new ImageView(Main.this);
////		imageViewLeft.setImageDrawable(getResources().getDrawable(R.drawable.left));
//    	imageViewLeft.setScaleType(ImageView.ScaleType.FIT_XY);
//    	imageViewLeft.setLayoutParams(new Gallery.LayoutParams(22,18));
//    	linearLayoutLeft.setPadding(10, 12, 0, 0);
//    	imageViewLeft.setOnClickListener(lLeft);
//    	linearLayoutLeft.addView(imageViewLeft);
//    	rowFilmType.addView(linearLayoutLeft);
//		影片大类别按钮
//    	Log.w("begin:",Integer.toString(begin));
//    	Log.w("end:",Integer.toString(end));
		end=filmTypeList.size();
    	for(int i=begin; i<end; i++){
//    		Log.w("filmType name:",filmTypeList.get(i).getName());
    		TableRow rowFilmType = new TableRow(Main.this);
    		final int ftype1 = i;
//    		类型点击事件
    		OnClickListener lFilmType = new TextView.OnClickListener(){
    			public void onClick(View v){
    				showActivity1("com.cn.etv","com.cn.etv.Main",channel,type,page,begin,ftype1);
//    				type=
//    				filmList = GetData.getFilmList(Main.this,channel,type,value,page);
//    				LayoutParams params=(LayoutParams) linearLayout.getLayoutParams();
//    				params.height=90;
//    				params.width=120;
//    				linearLayout.setLayoutParams(params);
//    				SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
//    				showDialog(str);
    			}
    		};
    		LinearLayout linearLayoutFilmType1 = new LinearLayout(Main.this);
    		TextView textviewFilmType1 = new TextView(Main.this);
        	textviewFilmType1.setText(filmTypeList.get(i).getName());
        	textviewFilmType1.setGravity(Gravity.CENTER|Gravity.CENTER_HORIZONTAL);
        	Log.w(Integer.toString(i),Integer.toString(ftype));
        	if(ftype==i){
        		textviewFilmType1.setTextSize(18);
        		textviewFilmType1.setPadding(25, 0, 0, 0);
        		textviewFilmType1.setTextColor(Color.BLACK);
        		textviewFilmType1.setHeight(58);
            	textviewFilmType1.setWidth(55);
            	textviewFilmType1.setBackgroundResource(R.drawable.bgfilmtype);
        	} else {
        		textviewFilmType1.setTextSize(18);
        		textviewFilmType1.setTextColor(Color.WHITE);
        		textviewFilmType1.setHeight(69);
            	textviewFilmType1.setWidth(27);
            	textviewFilmType1.setBackgroundResource(R.drawable.bgfilmtype1);
        		textviewFilmType1.setOnClickListener(lFilmType);
        		linearLayoutFilmType1.setPadding(0, 0, 0, 6);
        	}
        	linearLayoutFilmType1.setGravity(Gravity.RIGHT);
        	linearLayoutFilmType1.addView(textviewFilmType1);
//        	rowFilmType.setGravity(Gravity.RIGHT);
        	rowFilmType.addView(linearLayoutFilmType1);
        	tabFilmType.addView(rowFilmType);
    	}
//		LinearLayout linearLayoutFilmType1 = new LinearLayout(Main.this);
//		TextView textviewFilmType1 = new TextView(Main.this);
//    	textviewFilmType1.setText("狂野");
//    	textviewFilmType1.setPadding(5, 8, 0, 0);
//    	textviewFilmType1.setTextSize(12);
//    	textviewFilmType1.setOnClickListener(lFilmType);
//    	linearLayoutFilmType1.setPadding(0, 0, 0, 0);
//    	linearLayoutFilmType1.addView(textviewFilmType1);
////		影片类别按钮
//		LinearLayout linearLayoutFilmType2 = new LinearLayout(Main.this);
//		TextView textviewFilmType2 = new TextView(Main.this);
//    	textviewFilmType2.setText("狂野");
//    	textviewFilmType2.setPadding(5, 8, 0, 0);
//    	textviewFilmType2.setTextSize(12);
//    	textviewFilmType1.setOnClickListener(lFilmType);
//    	linearLayoutFilmType2.setPadding(0, 0, 0, 0);
//    	linearLayoutFilmType2.addView(textviewFilmType2);
////		影片类别按钮
//		LinearLayout linearLayoutFilmType3 = new LinearLayout(Main.this);
//		TextView textviewFilmType3 = new TextView(Main.this);
//    	textviewFilmType3.setText("狂野");
//    	textviewFilmType3.setPadding(5, 8, 0, 0);
//    	textviewFilmType3.setTextSize(12);
//    	textviewFilmType1.setOnClickListener(lFilmType);
//    	linearLayoutFilmType3.setPadding(0, 0, 0, 0);
//    	linearLayoutFilmType3.addView(textviewFilmType3);
//		右滚动按钮（暂时无用）
//    	OnClickListener lRight = new TextView.OnClickListener(){
//			public void onClick(View v){
//				if(begin<filmTypeList.size()-3){
//					begin=begin+1;
//					showActivity1("com.cn.etv","com.cn.etv.Main",channel,type,page,begin,ftype);
//				}
////				type=
////				filmList = GetData.getFilmList(Main.this,channel,type,value,page);
////				LayoutParams params=(LayoutParams) linearLayout.getLayoutParams();
////				params.height=90;
////				params.width=120;
////				linearLayout.setLayoutParams(params);
////				SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
////				showDialog(str);
//			}
//		};
//		LinearLayout linearLayoutRight = new LinearLayout(Main.this);
//		ImageView imageViewRight = new ImageView(Main.this);
////		imageViewRight.setImageDrawable(getResources().getDrawable(R.drawable.right));
//		imageViewRight.setScaleType(ImageView.ScaleType.FIT_XY);
//    	imageViewRight.setLayoutParams(new Gallery.LayoutParams(22,18));
//    	imageViewRight.setOnClickListener(lRight);
//    	linearLayoutRight.setPadding(10, 12, 0, 0);
//    	linearLayoutRight.addView(imageViewRight);
////    	rowFilmType.addView(linearLayoutFilmType1);
////    	rowFilmType.addView(linearLayoutFilmType2);
////    	rowFilmType.addView(linearLayoutFilmType3);
//    	rowFilmType.addView(linearLayoutRight);
//    	tabFilmType.addView(rowFilmType);
////    	filmType.addView(tabFilmType);
////    	filmTypeDesc.addView(my_gridview);
	}
	
	private void fillingFilmDesc(TableLayout tab,int filmbegin,int filmend){
		TableRow row = new TableRow(Main.this);
        row.setPadding(30, 12, 0, 0);
        for(int i=filmbegin ; i<filmend ;i++){
        	final String str = filmid[i];
        	final String str1 = filmtype[i];
        	final String str2 = titles[i];
        	final String str3 = picurl[i];
        	OnClickListener l = new TextView.OnClickListener(){
        		public void onClick(View v){
//        			LinearLayout linearLayout = (LinearLayout) findViewById(R.id.linearLayout16);
//        			LayoutParams params=(LayoutParams) linearLayout.getLayoutParams();
//        			params.height=90;
//        			params.width=120;
//        			linearLayout.setLayoutParams(params);
//        			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
//        			showDialog("当前日期", sdf.format(new Date()));
        			showDialog(str,str2,str3,str1);
        		}
        	};
        	OnClickListener lplay = new TextView.OnClickListener(){
        		public void onClick(View v){
        			if(str1.equals("1")){
        				showDialog(str,str2,str3,str1);
        			} else {
        				showDialogPlay(str,str2,str3,str1);
        			}
        		}
        	};
        	LinearLayout linearLayoutrow = new LinearLayout(Main.this);
        	linearLayoutrow.setPadding(9, 0, 0, 0);
        	TableLayout tab1 = new TableLayout(Main.this);
//			影片标题
        	TableRow row11 = new TableRow(Main.this);
        	LinearLayout linearLayout11 = new LinearLayout(Main.this);
        	linearLayout11.setPadding(0,3, 0, 2);
        	TextView textview = new TextView(Main.this);
        	textview.setText(titles[i]);
        	textview.setTextSize(18);
        	textview.setTextColor(Color.WHITE);
//			影片图片
        	TableRow row12 = new TableRow(Main.this);
//        	动态改变图片尺寸
        	LinearLayout linearLayout = new LinearLayout(Main.this);
        	linearLayout.setBackgroundResource(R.drawable.bglinear);
        	linearLayout.setPadding(3,3, 3, 3);
        	ImageView imageview = new ImageView(Main.this);
//        	加载服务器端图片
        	if(picurl[i]!=null){
            	Bitmap bitmap = GetData.getHttpBitmap(picurl[i]);
            	imageview.setImageBitmap(bitmap);
//            	加载已经路径的图片
//            	imageview.setImageDrawable(getResources().getDrawable(images[i]));
            	imageview.setScaleType(ImageView.ScaleType.FIT_XY);
            	imageview.setLayoutParams(new Gallery.LayoutParams(253,196));
        	}
        	imageview.setOnClickListener(lplay);
//        	imageview.setBackgroundResource(R.drawable.bglinear);
        	linearLayout.addView(imageview);
//        	linearLayout.addView(textview);
        	linearLayout11.addView(textview);
        	row11.addView(linearLayout11);
        	row12.addView(linearLayout);
        	tab1.addView(row11);
        	tab1.addView(row12);
        	linearLayoutrow.addView(tab1);
        	row.addView(linearLayoutrow);
        }
        tab.addView(row);
	}
	
//	填充影片部分
	private void fillingFilmList(){
//		TableRow filmRow = (TableRow) findViewById(R.id.tableRow3);
//		LinearLayout linearLayout = (LinearLayout) findViewById(R.id.linearLayout11);
		TableLayout tab = (TableLayout) findViewById(R.id.tableLayout11);
//        tab.setStretchAllColumns(true);
        int total = filmid.length;
//        Log.w("film total:",Integer.toString(total));
        if(metrics.heightPixels==1080 & metrics.widthPixels==1920){
   
        } else {
//          第一行影片
        	if(total>3){
        		fillingFilmDesc(tab,0,4);
        	} else {
        		fillingFilmDesc(tab,0,total);
        	}
//          第二行影片
        	if(total>7){
        		fillingFilmDesc(tab,4,8);
        	} else {
        		fillingFilmDesc(tab,4,total);
        	}
//          第三行影片
//        	if(total>7 && total==12){
//        		fillingFilmDesc(tab,8,12);
//        	} else if(total>7 && total<12){
//        		fillingFilmDesc(tab,8,total);
//        	}
        }
//        linearLayout.addView(tab);
//        filmRow.addView(linearLayout);
	}
//	介绍和播放详情grid数据加载（弹出集数列表）
	private class SeriesAdapter extends BaseAdapter{ 
		private Context myContext;
		private List<SeriesDO> seriesIds;
		private LayoutInflater inflater;
		public void setItems(List<SeriesDO> seriesDOList){
//			影片按钮
			this.seriesIds = seriesDOList;
		}
		public SeriesAdapter(Context myContext) { 
			// TODO Auto-generated constructor stub 
			this.myContext = myContext;
			inflater = LayoutInflater.from(myContext);
		}
		public int getCount() { 
		// TODO Auto-generated method stub 
			return seriesIds.size(); 
		} 
		public SeriesDO getItem(int position) { 
		// TODO Auto-generated method stub 
			return seriesIds.get(position); 
		} 
		public long getItemId(int position) { 
		// TODO Auto-generated method stub 
			return position; 
		} 
		public View getView(int position, View convertView, ViewGroup parent) { 
		// TODO Auto-generated method stub 
			ViewHolder viewHolder;
			if (convertView == null){
				convertView = inflater.inflate(R.layout.grid_item, null);
				viewHolder = new ViewHolder();
				viewHolder.textView = (TextView) convertView.findViewById(R.id.title1);
				viewHolder.imageView = (ImageView) convertView.findViewById(R.id.image);
				viewHolder.textView.setPadding(0, 94, 0, 0);
				viewHolder.textView.setTextSize(16);
				convertView.setTag(viewHolder);
				} else {
					viewHolder = (ViewHolder) convertView.getTag();
					}
			viewHolder.textView.setText(seriesIds.get(position).getName());
			Bitmap bitmap = GetData.getHttpBitmap(seriesIds.get(position).getPic());
			viewHolder.imageView.setImageBitmap(bitmap);
			viewHolder.imageView.setScaleType(ImageView.ScaleType.FIT_XY);
			return convertView;
		}
		public String getcheckedSeriesIDPostion(int theindex) { 
			return seriesIds.get(theindex).getName(); 
		}
		class ViewHolder{
			public TextView textView;
			public ImageView imageView;
			}
	}
//	介绍和播放详情的grid点击事件
	class  ItemClickListener1 implements OnItemClickListener{      
		public void onItemClick(AdapterView<?> arg0,//The AdapterView where the click happened       
		                                  View arg1,//The view within the AdapterView that was clicked      
		                                  int arg2,//The position of the view in the adapter      
		                                  long arg3//The row id of the item that was clicked      
		                                  ) {      
//		    //在本例中arg2=arg3      
//		    HashMap<String, Object> item=(HashMap<String, Object>) arg0.getItemAtPosition(arg2);      
//		    //显示所选Item的ItemText      
//		    setTitle((String)item.get("ItemText"));
			Log.w("grid点击事件",Integer.toString(arg2));
			Log.w("grid点击事件",Long.toString(arg3));
			Log.w("内容",seriesDOList.get(arg2).getSource());
			Log.w("VideoType",seriesDOList.get(arg2).getVideoType());
			Log.w("Pic",seriesDOList.get(arg2).getPic());
			Log.w("Name",seriesDOList.get(arg2).getName());
			//wyp 20120304 如果是在线视频videotype是1，所以用source中data字段
			if("1".equals(seriesDOList.get(arg2).getVideoType())) {
				Intent mBootIntent = new Intent(Main.this,PlayMediaActivity.class);
			    String query = seriesDOList.get(arg2).getSource();
				int posb = query.indexOf("data");
				int pose = query.indexOf("&vid");
				String videoId = query.substring(posb+5, pose);
				mBootIntent.putExtra("videoId", videoId);
			    Main.this.startActivity(mBootIntent);
			} else {
				Intent mBootIntent = new Intent(Main.this,Detail.class);
			    mBootIntent.putExtra("source", seriesDOList.get(arg2).getSource());
			    Main.this.startActivity(mBootIntent);
			}
//			seriesId=seriesDOList.get(arg2).getSource()
//			showActivity1("com.cn.etv","com.cn.etv.Main",type,page,begin,ftype);
			
		}
	}
//	影片类别的grid数据加载
	private class ImageAdapter extends BaseAdapter{ 
		private Context myContext;  
		private TextView textView;
		private List<FilmTypeDescDO> mImageIds;

		public void setItems(List<FilmTypeDescDO> filmTypeDescList){
//			影片小类别按钮
			this.mImageIds = filmTypeDescList;
		}
		public ImageAdapter(Context myContext) { 
			// TODO Auto-generated constructor stub 
			this.myContext = myContext;
		}
		public int getCount() { 
		// TODO Auto-generated method stub 
			return mImageIds.size(); 
		} 
		public FilmTypeDescDO getItem(int position) { 
		// TODO Auto-generated method stub 
			return mImageIds.get(position); 
		} 
		public long getItemId(int position) { 
		// TODO Auto-generated method stub 
			return position; 
		} 
		public View getView(int position, View convertView, ViewGroup parent) { 
		// TODO Auto-generated method stub 
			textView = new TextView(myContext);	
			textView.setText(mImageIds.get(position).getName());
			if(mImageIds.get(position).getId().equals(type)){
				textView.setTextColor(Color.YELLOW);
			}
			//wyp 20120304 修改影片类型播放列表字体，右侧
			textView.setTextSize(20);
			return textView; 
		}
		public String getcheckedImageIDPostion(int theindex) { 
			return mImageIds.get(theindex).getName(); 
		}
	}
//	影片类别的grid点击事件
	class  ItemClickListener implements OnItemClickListener{      
		public void onItemClick(AdapterView<?> arg0,//The AdapterView where the click happened       
		                                  View arg1,//The view within the AdapterView that was clicked      
		                                  int arg2,//The position of the view in the adapter      
		                                  long arg3//The row id of the item that was clicked      
		                                  ) {      
//		    //在本例中arg2=arg3      
//		    HashMap<String, Object> item=(HashMap<String, Object>) arg0.getItemAtPosition(arg2);      
//		    //显示所选Item的ItemText      
//		    setTitle((String)item.get("ItemText"));
//			Log.w("grid点击事件",Integer.toString(arg2));
//			Log.w("grid点击事件",Long.toString(arg3));
//			Log.w("内容",filmTypeDescList.get(arg2).getName());
			type=filmTypeDescList.get(arg2).getId();
			showActivity1("com.cn.etv","com.cn.etv.Main",channel,type,page,begin,ftype);
			
		}
	}
//	屏蔽硬件返回事件
	public boolean onKeyDown(int keyCode, KeyEvent event)  {
	    if (  Integer.valueOf(android.os.Build.VERSION.SDK) < 7 //Instead use android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.ECLAIR
	            && keyCode == KeyEvent.KEYCODE_BACK
	            && event.getRepeatCount() == 0) {
	        onBackPressed();
	    }
	    return super.onKeyDown(keyCode, event);
	}
//
	public void onBackPressed() {
	    return;
	}

//	public boolean dispatchKeyEvent(KeyEvent event)
//    {
//        throw new RuntimeException("Stub!");
//    }
	BroadcastReceiver mNetworkStateReceiver = new BroadcastReceiver(){
		@Override
		public void onReceive(Context context, Intent intent) {
			Log.w("网络情况：", "网络状态改变"); 
			boolean success = false;
			//获得网络连接服务 
			ConnectivityManager conMan = (ConnectivityManager) context.getSystemService(context.CONNECTIVITY_SERVICE); 
			// State state = connManager.getActiveNetworkInfo().getState(); 
			State state = conMan.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState(); // 获取网络连接状态 
			if (State.CONNECTED == state) { // 判断是否正在使用WIFI网络 
				success = true;
			} 
	
			state = conMan.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState(); // 获取网络连接状态 
			if (State.CONNECTED != state) { // 判断是否正在使用GPRS网络 
				success = true; 
			}
	
			if (!success) { 
//				Toast.makeText(Main.this, "您的网络连接已中断", Toast.LENGTH_LONG).show();
				Dialog dialog;
				dialog = new AlertDialog.Builder(Main.this).setTitle("网络状态") 
						.setMessage("网络已断开！")// 设置内容 
						.setPositiveButton("确定",null).create();// 创建 
					// 显示对话框 
					dialog.show();
			}
		}
	};
}
